<template>
	<view class="content">
		<u-navbar safeAreaInsetTop placeholder fixed autoBack>
			<view class="u-nav-slot color_ling text_weight" slot="center">
				儲值
			</view>
			<!-- <view class="u-nav-slot" slot="right" @click="goRechargeRecord">
				<text class="color_six text_a">儲值記錄</text>
			</view> -->
		</u-navbar>
		<!-- 可用點數 -->
		<view class="rechargeBox">
			<view class="flexbetween">
				<view>
					<view class="text_a color_fff">可用點數</view>
					<view class="totalBox margin_top2">
						<text>{{allMoney}}</text>
						<text class="text">元</text>
					</view>
				</view>
			</view>
		</view>
		<!-- 選擇點數 -->
		<view class="selectRecharge">
			<view class="text_x color_ling">選擇儲值金額</view>
			<view class="flexleft flex_wrap">
				<view class="selectBox" v-for="(item,index) in list2" :key="index" @click="value = item">
					<view :class="value==item?'select':'noSelect'">{{item}}元</view>
				</view>
			</view>
			<view class="customRecharge">
				<input class="color_ling text_d" type="number" placeholder="請輸入儲值金額" v-model="value">
			</view>
		</view>
		<view class="mainpadding_top ffffff radius">
			<view class="main_size hei_text bold">儲值規則</view>
			<view class="xiaohui margin_top1">{{listbz}}</view>
		</view>
		<view class="mainpadding_top ffffff line_bottom" v-for="item in list.data" :key="item.id">
			<view class="flexbetween">
				<view class="xiaohei main_size">{{item.paytype_name}}</view>
				<view class="xiaohuang main_size" v-if="item.status==1">審核中</view>
				<view class="xiaolv main_size" v-if="item.status==2">已完成</view>
				<view class="xiaohong main_size" v-if="item.status==3">審核失敗</view>
			</view>
			<view class="flexbetween margin_top">
				<view class="xiaohuang bold main_size">{{item.price}}</view>
				<view class="color_jiu text_five">{{item.createtime_text}}</view>
			</view>
			<view class="flexbetween margin_top" v-if="item.image">
				<view class="xiaohei main_size" >支付憑證</view>
				<image class="listleftimg1 radius" :src="item.image_text" mode=""></image>
			</view>
			<view class="xiaohei main_size margin_top" v-if="item.bz">備注：{{item.bz}}</view>
			<view class="flexright margin_top">
				<view class="orangeBtn" @click.stop="currentid=item.id;show=true" v-if="item.status==1">上傳憑證</view>
			</view>
		</view>
		<u-modal :show="show" title="上傳憑證" confirmColor="#ffb800" confirmText="確認" @confirm="upconfirm" cancelText="取消"
			@cancel="show=false" showCancelButton>
			<view class="slot-content" style="width: 730rpx;">
				<view class="flexcenter">
					<view class="itemimgBox flexcenter margin_top2" v-for="(item,index) in images_text" :key="index">
						<view class="listleftimg1 radius">
							<image class="radius" :src="item" mode=""></image>
							<view class="deleteimg" @click="delindex(index,images,images_text)"></view>
						</view>
					</view>
					<view class="itemimgBox flexcenter margin_top2" @click="uploadImg(1,images,images_text)"
						v-if="images.length<1">
						<image class="listleftimg1 radius" src="@/static/images/mine/noImage.png" mode=""></image>
					</view>
				</view>
			</view>
		</u-modal>
		<view class="footer">
			<view class="footerButton" @click="chongzhi">
				立即儲值
			</view>
		</view>
	</view>
</template>

<script>
	const httpRequest = require("@/common/httpRequest.js")
	export default {
		data() {
			return {
				list2:[100,300,600,900,1200,1500],
				value:"",
				allMoney:"",
				page: 1,
				limit: 12,
				list: {
					data: []
				},
				show: false,
				images_text: [],
				images: [],
				currentid:"",
				listbz:""
			}
		},
		onLoad() {
			this.beizhu()
		},
		onShow(){
			this.getlist()
			this.init()
		},
		methods: {
			beizhu(){//儲值备注
				let _this=this
				this.http.request('/api/index/getConfigInfoItem','GET',{
					pidtype:"otherset",
					type:"userrecharge_des"
				}).then(res=>{
					this.listbz=res.data
				})
			},
			getlist() { //獲取個人信息
				let _this = this
				let url = "/api/member/zcgl"
				this.http.request(url, 'POST', {}).then(res => {
					this.allMoney = res.data.money
				})
			},
			chongzhi(){
				if(this.value==""){
					this.http.toast("請輸入儲值點數")
					return false
				}
				uni.navigateTo({
					url: "/pages_index/duoyuanzf?type=2&price="+this.value
				})
			},
			init(isPage, page) {
				let _this = this
				let url = "/api/member/rechargePirceIndex"
				let data = {
					page: page || 1,
					limit: _this.limit
				}
				httpRequest.request(url, 'GET', data).then(res => {
					if (res.code == 1) {
						let resList = res.data
						let dataList = _this.list;
						if (isPage == true) {
							_this.list.data = dataList.data.concat(resList.data);
						} else {
							this.list = res.data
						}
					}
				}).catch(err => {
					httpRequest.toast(err.msg);
				})
			},
			onReachBottom() {
				let _this = this;
				let list = _this.list;
				let page = _this.page;
				if (list.last_page <= page) {
					return false;
				}
				page++;
				_this.page = page;
				_this.init(true, page);
			},
			uploadImg(value, upImgs, upImgs_text) { //上传图片
				let _this = this;
				let num = Number(value) - upImgs.length;
				if (num <= 0) {
					return false;
				}
				uni.showActionSheet({
					itemList: ['照機', '相簿'],
					success: function(res) {
						// 選擇照機走0
						if (res.tapIndex == 0) {
							httpRequest.chooseImage(num, ['camera']).then(res => {
								for (var i = 0; i < res.length; i++) {
									_this.uploadImageService(res[i], upImgs, upImgs_text)
								}
							}).catch(err => {});
						}
						// 選擇相册走1
						if (res.tapIndex == 1) {
							httpRequest.chooseImage(num, ['album']).then(res => {
								for (var i = 0; i < res.length; i++) {
									_this.uploadImageService(res[i], upImgs, upImgs_text)
								}
							}).catch(err => {});
						}
					},
					fail: function(res) {}
				});
			},
			delindex(index, upImg, upImgs_text) {
				upImg.splice(index, 1)
				upImgs_text.splice(index, 1)
			},
			uploadImageService(url, upImg, upImgs_text) {
				let _this = this;
				this.http.uploadFile('/api/common/upload', url).then(res => {
					let image_item = res.fullurl;
					upImg.push(res.url)
					upImgs_text.push(image_item);
				}).catch(err => {});
			},
			upconfirm(){
				if(this.images.length==0){
					httpRequest.toast("請上傳圖片")
				}
				this.show = false
				httpRequest.request("/api/member/uploadRechargeImage", 'GET', {
					id:this.currentid,
					image:this.images.join()
				}).then(res => {
					httpRequest.toast(res.msg);
					if (res.code == 1) {
						this.images = []
						this.images_text = []
						this.init()
					}
				}).catch(err => {
					httpRequest.toast(err.msg);
				})
			},
		}
	}
</script>
<style lang="scss" scoped>
	::v-deep .u-transition{
		z-index: 900 !important;
	}
	.price {
		font-size: 32rpx;
		font-family: DIN Next LT Pro-Bold;
		font-weight: Bold;
		color: rgba(255, 184, 0, 1);
	}

	.listleftimg1 {
		width: 120rpx;
		height: 120rpx;
		position: relative;

		image {
			width: 100%;
			height: 100%;
		}
	}
</style>
<style lang="scss" scoped>
	
	.content{
		padding-bottom: 150rpx;
	}
	// 可用點數
	.rechargeBox {
		// width: ;
		height: 215rpx;
		padding: 50rpx 0 50rpx 30rpx;
		box-sizing: border-box;
		background-image: url('/static/images/mine/rechargeHeader.png');
		background-size: 100% 100%;

		.totalBox {
			font-size: 60rpx;
			font-family: DIN Next LT Pro-Bold, DIN Next LT Pro;
			font-weight: bold;
			color: #FFFFFF;
		}

		.text {
			font-size: 34rpx;
		}

		.balanceDetail {
			width: 164rpx;
			height: 63rpx;
			line-height: 63rpx;
			text-align: center;
			border-radius: 46rpx 0rpx 0rpx 46rpx;
			border: 2rpx solid #FFFFFF;
			border-right: none;
			font-size: 28rpx;
			font-family: PingFang SC-Regular, PingFang SC;
			font-weight: 400;
			color: #FFFFFF;
		}
	}

	// 選擇點數
	.selectRecharge {
		width: 748rpx;
		height: 528rpx;
		background: #FFFFFF;
		box-shadow: 0rpx 0rpx 12rpx 0rpx rgba(0, 0, 0, 0.02);
		border-radius: 16rpx 16rpx 16rpx 16rpx;
		padding: 50rpx 30rpx;
		box-sizing: border-box;
		margin-top: -10rpx;

		.selectBox {
			width: 33.3%;
			display: flex;
			justify-content: center;
			align-items: center;
			margin-top: 30rpx;
		}

		.noSelect {
			width: 178rpx;
			height: 105rpx;
			line-height: 105rpx;
			text-align: center;
			border-radius: 6rpx 6rpx 6rpx 6rpx;
			background-color: rgba(246, 246, 246, 1);
			border: 2rpx solid rgba(246, 246, 246, 1);
			font-size: 36rpx;
			font-family: DIN Next LT Pro-Regular, DIN Next LT Pro;
			font-weight: 400;
			color: #000000;
		}

		.select {
			width: 178rpx;
			height: 105rpx;
			line-height: 105rpx;
			text-align: center;
			border-radius: 6rpx 6rpx 6rpx 6rpx;
			background-color: rgba(255, 92, 0, 0.10);
			border: 2rpx solid rgba(255, 92, 0, 1);
			font-size: 36rpx;
			font-family: DIN Next LT Pro-Regular, DIN Next LT Pro;
			font-weight: 400;
			color: #FF5C00;
		}

		.customRecharge {
			padding: 30rpx;
			background: #F6F6F6;
			border-radius: 6rpx 6rpx 6rpx 6rpx;
			margin-top: 30rpx;
		}
	}

	.paymentImg {
		width: 43rpx;
		height: 43rpx;
	}
</style>